package com.atelier.plugin.database.ui;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class DropdownTextField extends JPanel {
    private JTextField textField;
    private JComboBox<String> comboBox;

    public DropdownTextField(String... dropdownItems) {
        setLayout(new BorderLayout());

        // 创建文本输入框
        textField = new JTextField();
        add(textField, BorderLayout.CENTER);

        // 创建下拉框
        comboBox = new JComboBox<>(dropdownItems);
        add(comboBox, BorderLayout.EAST);

        // 监听下拉框选择事件
        comboBox.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                // 获取选择的下拉项并设置到文本框中
                String selectedValue = (String) comboBox.getSelectedItem();
                textField.setText(selectedValue);
            }
        });
    }

    // 获取文本框的文本
    public String getText() {
        return textField.getText();
    }

    // 设置文本框的文本
    public void setText(String text) {
        textField.setText(text);
    }

}
